package managers.dateManager.endFrozen.beginChange;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

import org.apache.log4j.Logger;
import org.tbjd.client.beans.Task;
import org.tbjd.client.constants.NotificationsConstants;
import org.tbjd.client.exceptions.DateManagerException;
import org.tbjd.client.managers.TaskManager;
import org.tbjd.client.states.StateEndFrozenSPEC;

import factories.TaskFactory;

/**
 * <p>
 * Test TaskManager's methods when BeginDate changed
 * </p>
 * <p>
 * <b>Case</b>
 * </p>
 * <p>
 * Task with BeginDate frozen and no relationships (predecessors/successors)
 * </p>
 * <p>
 * <b> Expected</b>
 * <ul>
 * <li>update Duration</li>
 * <li>update Successors</li>
 * </ul>
 * </p>
 * 
 * @author Michael Martin
 * @author Antonio Carrozzini
 * @version 1.0
 * 
 */
public class EndFrozen_BeginChange_Exceptions extends TestCase {

	private Task task = null;
	private Map<Integer, Object> map = null;
	private Logger log = Logger.getLogger("console");
	private DateFormat df = DateFormat.getInstance();
	private TaskManager dateManager = new TaskManager();

	protected void setUp() throws Exception {
		df = new SimpleDateFormat("dd.MM.yyyy");

		this.task = (Task) TaskFactory.getInstance();
		this.task.setDurationModeByRatios(false);
		task.setState(new StateEndFrozenSPEC(task.getState().getDurationModeState()));

		super.setUp();
	}

	public void testExceptions() {
		System.out.println("");

		Date newBeginDate = null;
		try {
			newBeginDate = df.parse("3.6.2009");

		} catch (ParseException e1) {
			fail(e1.getMessage());

		}
		log.debug("new BeginDate = " + newBeginDate);

		this.map = new HashMap<Integer, Object>();
		this.map.put(NotificationsConstants.TASKMANAGER_ACTION_beginDate, newBeginDate);
		this.map.put(NotificationsConstants.TASKMANAGER_BEAN, task);
		this.map.put(NotificationsConstants.TASKMANAGER_SENDER, null);

		log.debug("call TaskManager...");
		try {
			dateManager.manageDates(map);
			fail();

		} catch (DateManagerException e) {
			assertNotNull(e.getMessage());

		}

	}
}